package jsu.blogger.mapper;

import jsu.blogger.pojo.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Insert("insert into blog_system_database.messages (sender_id, receiver_id, content, created_at, is_accepted) values(#{senderId},#{receiverId},#{content},#{createdAt}, #{isAccepted})")
    int insertMessage(Message message);
    @Update("update blog_system_database.messages set is_accepted=1 where message_id=#{messageID}")
    int updateMessage(@Param("message_id") Long messageId);
    @Select("select message_id from blog_system_database.messages where is_accepted=0 ")
    List<Long> getAllNotAcceptedMessageIds();
    @Select("select message_id from blog_system_database.messages where is_accepted=0 and sender_id=#{senderId} ")
    List<Long> getUnAcceptedMessageIdsBySenderId(@Param("senderId") Long senderId);
    @Select("select message_id from blog_system_database.messages where is_accepted=0 and sender_id=#{receiverId} ")
    List<Long> getUnAcceptedMessageIdsByReceiverId(@Param("receiverId") Long receiverId);
}